package servlet;

import mapper.StudentMapper;
import pojo.Student;
import utils.MybatisUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author leiHua
 * @Date 2022/11/24 18:41
 */
@WebServlet("/updateStudentServlet")
public class UpdateStudentServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String num = request.getParameter("num");
        String name = request.getParameter("name");
        String id = request.getParameter("id");
        String sex = request.getParameter("sex");
        Student student = new Student();
        student.setId(Integer.parseInt(id));
        student.setNum(num);
        student.setName(name);
        student.setGender(sex);
        StudentMapper mapper = MybatisUtils.getSqlSession().getMapper(StudentMapper.class);
        mapper.updateStudent(student);
        response.sendRedirect("ShowAllStudentsServlet");
    }
}
